/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package service.system.impl;

import dao.system.SystemReportDao;
import java.util.List;
import javax.swing.tree.DefaultMutableTreeNode;
import model.system.SystemReport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import service.system.SystemReportService;
import view.ReportNode;

/**
 *
 * @author Yusup Jauhari Shandi <in.visi>
 */
@Service("systemReportService")
@Transactional(readOnly=true)
public class SystemReportServiceImpl implements SystemReportService{

    @Autowired private SystemReportDao systemReportDao;
    @Transactional(readOnly=false)
    
    @Override
    public SystemReport getSystemReport(int id) {
        return systemReportDao.getById(id);
    }

    @Override
    public List<SystemReport> getSystemReport() {
        return systemReportDao.getAll();
    }

    @Override
    public List<SystemReport> getSystemReport(int start, int num) {
        return systemReportDao.getAll(start, num);
    }

    @Override
    public List<SystemReport> getAll(int start, int num, String params, String orderBy) {
        return systemReportDao.getAll(start, num, params, orderBy);
    }

    @Override
    public DefaultMutableTreeNode getTreeReport(String reportGroup) {
        
        DefaultMutableTreeNode root = new DefaultMutableTreeNode("LAPORAN ".concat(reportGroup.toUpperCase()));
        List<SystemReport> list = this.getAll(0, 1000," where report_group = '"+reportGroup+"'", "");
        for (SystemReport rpt : list){
            root.add(new DefaultMutableTreeNode(new ReportNode(rpt.getReportId(), rpt.getReportGroup(), rpt.getReportName(),
                    rpt.getReportNameEn(), rpt.getPolicy(), rpt.getParentId(), rpt.getHide())));
            
        }
        return root;
    }
    
}
